package ua.crimea.bat.ss.model.beans;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;
import org.springframework.context.annotation.Lazy;

import javax.persistence.*;

/**
 * User: bat
 * Date: 21.03.2010
 * Time: 18:09:03
 */
@Entity
@Table(name = "images")
/*
@javax.persistence.SequenceGenerator(
        name = "SEQ_ID",
        sequenceName = "image_seq",
        allocationSize = 20)
*/
@PrimaryKeyJoinColumn(name="parent_id")
@Lazy(false)

public class Image extends BaseBean {

    private Album album;

    private String name;

    private byte[] image;

    private byte[] thumb;

    //@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_ID")

    @Column(length = 100)
    @LazyToOne(LazyToOneOption.FALSE)
    @Fetch(FetchMode.SELECT)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column
    //(columnDefinition="BLOB")
    @Lob
    @Basic(fetch = FetchType.EAGER)
    //@Type(type="BlobUserType")
    public byte[] getImage() {
        return image;
    }


    public void setImage(byte[] image) {
        this.image = image;
    }

    @Column
    //(columnDefinition="BLOB")
    @Lob
    @Basic(fetch = FetchType.EAGER)
    //@Type(type="BlobUserType")
    public byte[] getThumb() {
        return thumb;
    }

    public void setThumb(byte[] thumb) {
        this.thumb = thumb;
    }


    @ManyToOne(targetEntity = Album.class, fetch = FetchType.EAGER)
    @Fetch(FetchMode.SELECT)
    @JoinColumn(name = "album_id", nullable = false)
    public Album getAlbum() {
        return this.album;
    }

    public void setAlbum(Album album) {
        this.album = album;
    }

}
